package com.example.fangyh09.scrollview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    TextView tv;
    String str = "";
    ScrollView scroll;
    Button upbtn,downbtn;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.up:
                scroll.scrollBy(0, -30);
                break;
            case R.id.down:
                scroll.scrollBy(0,30);
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv = (TextView)findViewById(R.id.content);
        upbtn = (Button)findViewById(R.id.up);
        downbtn = (Button)findViewById(R.id.down);
        upbtn.setOnClickListener(this);
        downbtn.setOnClickListener(this);
        for (int i = 0;i < 100;i ++) {
            str += "a long \n";
        }
        tv.setText(str);
        scroll = (ScrollView)findViewById(R.id.scroll);
        scroll.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_UP:
                        break;
                    case MotionEvent.ACTION_DOWN:
                        break;
                    case MotionEvent.ACTION_MOVE:
                        if (scroll.getScrollY() <= 0) {

                        }
                        if (scroll.getChildAt(0).getMeasuredHeight() <= scroll.getHeight() + scroll.getY()) {

                        }
                        break;
                }
                return false;
            }
        });


    }
}






